/*  
    Copyright (C) <2007-2013>  <Kay Diefenthal>

    DD.UI.MediaCenter is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    DD.UI.MediaCenter is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with DD.UI.MediaCenter.  If not, see <http://www.gnu.org/licenses/>.
*/

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Threading;
using DD.UI.MediaCenter.Logging;
using DD.UI.MediaCenter.Properties;
using DD.UI.MediaCenter.ViewModels;
using Microsoft.MediaCenter.Hosting;

namespace DD.UI.MediaCenter
{
    public class AddIn : IAddInModule, IAddInEntryPoint
    {
        private Dictionary<string, object> _appInfo;
        private Dictionary<string, object> _entryPointInfo;

        public void Initialize(Dictionary<string, object> appInfo, Dictionary<string, object> entryPointInfo)
        {
            Logger.SetLogFilePath("AddIn.log", Settings.Default.LogLevel);
            _appInfo = appInfo;
            _entryPointInfo = entryPointInfo;
            Logger.Info(string.Format("{0}{1}{2}", "AddIn", "Initialize", ""));
        }

        public void Uninitialize()
        {
            Logger.Info(string.Format("{0}{1}{2}", "AddIn", "UnInitialize", ""));
        }

        public void Launch(AddInHost host)
        {
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(Settings.Default.Language);
            try
            {
                //Television
                if (String.Compare((string)_appInfo["id"], "{E82871AB-8C75-4f3f-9220-C31FBAB92BE7}", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    //Recordings
                    if (String.Compare((string)_entryPointInfo["id"], "{EB3404CF-3B24-4543-82E6-D86F949959CA}", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        new RecordedViewModel(new HistoryOrientedPageSession(), host).GoToRecordedView();
                    }
                    //Guide
                    if (String.Compare((string)_entryPointInfo["id"], "{F862DA72-C9F2-4c5a-8B64-183EC279834B}", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        new GuideViewModel(new HistoryOrientedPageSession(), host).GoToGuideView();
                    }
                    //Live
                    if (String.Compare((string)_entryPointInfo["id"], "{7327C1F3-5959-44d9-94F3-BE4EB6E70321}", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        new DefaultViewModel(new HistoryOrientedPageSession(), host).GoToDefaultView();
                    }
                    //Search
                    if (String.Compare((string)_entryPointInfo["id"], "{DB1F0BF2-C191-4ad0-B317-ABF6389811B0}", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        new SearchViewModel(new HistoryOrientedPageSession(), host).GoToSearchView();
                    }
                    //Settings
                    if (String.Compare((string)_entryPointInfo["id"], "{F930B103-97A2-41aa-9C15-AD46CB93DEDD}", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        new SettingsViewModel(new HistoryOrientedPageSession(), host).GoToSettingsView();
                    }
                }

                //Radio
                if (String.Compare((string)_appInfo["id"], "{370165A1-7DA0-4fff-B68F-9472513CA081}", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    //Recordings
                    if (String.Compare((string)_entryPointInfo["id"], "{C1B00CFD-57CB-4b13-BAA8-A9D6E6652EDB}", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        new RecordedViewModel(new HistoryOrientedPageSession(), host).GoToRecordedView();
                    }
                    //Guide
                    if (String.Compare((string)_entryPointInfo["id"], "{F22E900A-F839-4b2f-96B9-9DF013FBA310}", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        new GuideViewModel(new HistoryOrientedPageSession(), host).GoToGuideView();
                    }
                    //Live
                    if (String.Compare((string)_entryPointInfo["id"], "{C1662430-20F5-4ec5-83C7-2AE525D1E9F7}", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        new DefaultViewModel(new HistoryOrientedPageSession(), host).GoToDefaultView();
                    }
                    //Search
                    if (String.Compare((string)_entryPointInfo["id"], "{01460DA2-5433-4e52-9AEA-2EF9AA964387}", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        new SearchViewModel(new HistoryOrientedPageSession(), host).GoToSearchView();
                    }
                    //Settings
                    if (String.Compare((string)_entryPointInfo["id"], "{055B2AAA-0FE9-470b-A650-988ECDFA300E}", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        new SettingsViewModel(new HistoryOrientedPageSession(), host).GoToSettingsView();
                    }
                }
            }
            
            catch (Exception exception)
            {
                Logger.Error(string.Format("{0}{1}:{2}", "AddIn", "Launch", exception));
            }
        }
    }
}